﻿document.write(`<script type="text/javascript" src="/Login.js"></script>`);
var configInfo = InitialParameter("/Config.json");
let modelApi = configInfo["modelTree"].type + '://' + configInfo["modelTree"].value
function getUser() {
    var userInfo = getUserInfo();
    var userNo = (userInfo[0] && userInfo[0].hasOwnProperty("NO")) ? userInfo[0].NO : null;
    if (userNo==null) {
        alert("尚未登录，请登录后重试");
        return;
    }
    return userNo;
}
//用户名加密
function encrypt(userno) {
    var userASII = strToASII(userno);
    userASII = userASII.replace(/0/g, "%");
    userASII = userASII.replace(/1/g, "i");
    userASII = userASII.replace(/2/g, "h");
    userASII = userASII.replace(/3/g, "g");
    userASII = userASII.replace(/4/g, "f");
    userASII = userASII.replace(/5/g, "e");
    userASII = userASII.replace(/6/g, "d");
    userASII = userASII.replace(/7/g, "c");
    userASII = userASII.replace(/8/g, "b");
    userASII = userASII.replace(/9/g, "a");
    return userASII;
}
//用户名解密
function decrypt(userasii) {
    userasii = userasii.replace(/a/g, "9");
    userasii = userasii.replace(/b/g, "8");
    userasii = userasii.replace(/c/g, "7");
    userasii = userasii.replace(/d/g, "6");
    userasii = userasii.replace(/e/g, "5");
    userasii = userasii.replace(/f/g, "4");
    userasii = userasii.replace(/g/g, "3");
    userasii = userasii.replace(/h/g, "2");
    userasii = userasii.replace(/i/g, "1");
    userasii = userasii.replace(/%/g, "0");
    var userno = asiiToStr(userasii);
    return userno;
}
//获取用户机构ID
function getUserORG(userno) {
    return getCookie("portaluserdept");
    userno = userno ? userno : "";
    var thisResult = null;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/User/UserAshx.ashx",
        data: //发送到服务器的参数
          {
              stype: "getUserORG",
              userno: userno
          },
        datatype: "json",
        success: function (result) {
            thisResult = result;
        },
        error: function (err) {
            if (err.status == 405) {
                top.location.href = '/';
            }
            else {
                alert("信息读取错误（error:" + err.status + "）");
            }
                
        }
    });
    return thisResult;
}

//获取用户信息
function getUserInfo(userno) {
    userno = userno ? userno : getCookie("portaluserno");
    var thisResult = null;
    $.ajax({
        type: "post",
        async: false,
        url: modelApi + "/sw/user/getUserInfoByUserNo",
        data: //发送到服务器的参数
          {
              userNo: userno
          },
        datatype: "json",
        success: function (result) {
            let data = JSON.parse(result);
            if(data){
                for(var attr in data.data){
                    data.data[attr.toUpperCase()] = data.data[attr];
                }
            }
            thisResult = [data.data];
        }
    });
    return thisResult;
}

//获取用户中文名
function GetUserChinaName() {
    return getCookie("portalusername");
   // var thisResult = null;
   // $.ajax({
   //     type: "post",
   //     async: false,
   //     url: "/BaseAshx/User/UserManage.ashx",
   //     data: //发送到服务器的参数
   //       {
   //           mtype: "GetUserChinaName"
   //       },
   //     datatype: "json",
   //     success: function (result) {
   //         thisResult= result;
   //     },
   //     error: function (err) {
   //         if (err.status == 405)
   //             top.location.href = '/';
   //     }
   // });
   //return  thisResult;
}

//获取用户名
function GetUserNO() {
    return getCookie("portaluserno");
    //var thisresult = null;
    //$.ajax({
    //    type: "post",
    //    async: false,
    //    url: "/BaseAshx/User/UserManage.ashx",
    //    data: {
    //        mtype: "GetUserNo"
    //    },
    //    datatype: "json",
    //    success: function (result) {
    //        thisresult = result;
    //    },
    //    error: function (err) {
    //        if (err.status == 405)
    //            top.location.href = '/';
    //    }
    //})
    //return thisresult;
}